Skip to content

fix: preserve attribute-based list operations#344

Open
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/builder-list-attribute-operation
Open

fix: preserve attribute-based list operations#344
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/builder-list-attribute-operation

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 27, 2026

Summary

  • builds find/filter($List, Attribute = expression) as attribute-based list operations when possible
  • resolves the left-hand member to an attribute or association using the input list type
  • serializes FindByAttributeOperation / FilterByAttributeOperation to Microflows$Find / Microflows$Filter
  • adds builder and writer regression tests with generic model names

Why

The parser and formatter already know about attribute-based list operations, but mxcli exec rebuilt them as expression-based operations. That can produce an MPR that is textually stable but fails Studio Pro validation with CE0117 on the list operation activity.

Validation

  • make build
  • make lint-go
  • make test

Closes #343.
Related to #332.

Symptom: a `find($List, Attribute = expression)` or `filter($List, Attribute = expression)` statement could roundtrip textually but be rebuilt as an expression-based list operation that Studio Pro reports as CE0117.

Root cause: the parser and formatter already model Microflows$Find and Microflows$Filter as attribute-based operations, but the builder always produced FindByExpression/FilterByExpression and the writer did not serialize the attribute-based operation variants.

Fix: detect equality conditions whose left side is a list member, resolve the member to an attribute or association, build FindByAttributeOperation/FilterByAttributeOperation, and serialize those operations back to the Microflows$Find/Microflows$Filter storage types.

Tests: add a builder regression test for `find($Items, Code = $IteratorItem/ExternalCode)` and writer tests for attribute-based find plus association-based filter serialization.
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

  • The PR modifies cmd_microflows_builder_actions.go to add helper functions listAttributeOperation, listOperationFieldName, and resolveListOperationMember. While these are well-scoped to the file, they could potentially be made static (unexported) if they are only used within this file. However, since they are already unexported (lowercase first letter), this is acceptable.
  • The test in bugfix_regression_test.go uses a hardcoded variable type map (varTypes: map[string]string{"Items": "List of Demo.Item"}). This is acceptable for a unit test but could be made more flexible if reused. However, as a regression test for a specific fix, it is appropriate.

What Looks Good

  • The PR correctly addresses the core issue: preserving attribute-based list operations (FindByAttributeOperation/FilterByAttributeOperation) instead of falling back to expression-based operations when the condition is a simple attribute equality.
  • Changes are minimal and focused:
    • Added logic in cmd_microflows_builder_actions.go to detect simple attribute equality conditions and generate attribute-based operations.
    • Added BSON serialization support for the new operation types in writer_microflow_actions.go.
    • Added comprehensive regression tests covering both generation and serialization.
  • The fix follows the established pattern in the codebase (similar to how other list operations are handled).
  • Tests are well-structured and validate both the operation type and serialized BSON fields.
  • No changes to MDL syntax were needed (the fix works within existing parser/executor boundaries), so full-stack consistency checks for MDL features are not applicable.
  • The PR includes validation that the generated BSON matches Studio Pro expectations (Microflows$Find/Microflows$Filter types).

Recommendation

Approve the PR. The changes are minimal, well-tested, and directly resolve the reported Studio Pro validation issue (CE0117) by preserving attribute-based list operations when possible. The code follows existing patterns and maintains backward compatibility through the fallback to expression-based operations for complex conditions. No checklist violations were found.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Adds an MDL script under mdl-examples/bug-tests/ exercising
`find($List, Attribute = expression)` and
`filter($List, Attribute = expression)`. After exec, `mx check`
reports 0 errors, confirming the rebuild emits Microflows$Find /
Microflows$Filter with attribute-operation shape.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attribute-based find/filter list operations can roundtrip as invalid expressions

2 participants